//获取应用实例 
let time = require('../util/weapp-qrcode.js');
import QRCode from '../util/weapp-qrcode.js'
var app = getApp()
Page({
  data: {
    imgUrls: [],
    indicatorDots: true, //是否显示面板指示点
    autoplay: true, //是否自动播放
    interval: 6000, //停留时间间隔
    duration: 1000, //播放时长
    previousMargin: '50px', //前边距，可用于露出前一项的一小部分，接受 px 和 rpx 值
    nextMargin: '50px', //后边距，可用于露出后一项的一小部分，接受 px 和 rpx 值
    circular: true, //是否采用衔接滑动
    currentSwiperIndex: 0, //swiper当前索引
    newsUrl:[],
  },
  onShow:function(){
    
  },
  onReady:function(){
    this.getDeviceInfo();
  },
  getDeviceInfo: function () {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          deviceW: res.windowWidth,
          deviceH: res.windowHeight
        })
      }
    })
  },

  copyAuth: function (e) {
    console.log(e)
    wx.setClipboardData({
      data: e.currentTarget.dataset.text,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },
  swiperBindchange(e) {
    this.setData({
      currentSwiperIndex: e.detail.current
    })
  },
  onLoad: function () {
    this.getBannerList();
    this.setData({
      authCode:app.globalData.auth_code
    })
  },

  onReady: function () {
    wx.setNavigationBarTitle({
      title: '邀请好友'
    })
  },

//分享海报
  getBannerList(){
    var that=this;
    wx.request({
      url: app.globalData.api + '/app.php?c=Banner&a=getBannerList',
      method: 'post',
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      data: {
        cat_id: '' + app.globalData.sharedThree
      },
      success: (res) => {
        console.log(res)
        if (res.data.code == 0) {
          res.data.data.list.forEach((item) => {
            item.img = app.globalData.imgUrl+item.img; //要截取时间的字符串
          })
          that.setData({
            imgUrls:res.data.data.list,
            newsUrl: app.globalData.api + '/wap.php/UserAccount/register/referrer_id?referrer_id=' + app.globalData.uid
          })
          console.log(that.data.newsUrl)
          // var link = decodeURIComponent(that.data.newsUrl);
          // console.log(link);
          // var paramArr = link.split('=');
          // if (paramArr.length == 2) {
          //   var params = paramArr[1].split('_');
          //   console.log(params[0]);
          //   console.log(params[1]);
          // }
          new QRCode('myQrcode', {
            text: '' + that.data.newsUrl,
            width: 200,
            height: 200,
            padding: 12, // 生成二维码四周自动留边宽度，不传入默认为0
            correctLevel: QRCode.CorrectLevel.L, // 二维码可辨识度
            callback: (res) => {
              console.log(res.path)
              that.setData({
                urlImg:res.path
              })
              // 接下来就可以直接调用微信小程序的api保存到本地或者将这张二维码直接画在海报上面去，看各自需求
            }
          })
          // console.log(that.data.newsUrl)
        }
      },
    });
  },

  //分享海报 用户注册 获取二维码
  // getRegister() {
  //   var that = this;
  //   wx.request({
  //     url: app.globalData.api + '/index.php/wap/UserAccount/register2/referrer_id/$referrer_id',
  //     method: 'post',
  //     data: {
  //       referrer_id: '' + app.globalData.uid
  //     },
  //     success: (res) => {
  //       console.log(res)
  //       if (res.data.code == 1) {
  //       }
  //     },
  //   });
  // }
})
